<%@ page import="com.wzx.selfuse.entity.PlanPro" %>
<%@ page import="com.github.pagehelper.PageInfo" %><%--
  Created by IntelliJ IDEA.
  User: WZX
  Date: 2022/12/6
  Time: 14:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/resource/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="javascript:;">首页</a>
                <a href="javascript:;">计划进度</a>
                <a>
                    <cite>产品管理</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.href='proList'" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" action="checkPro" method="post">
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="controller">
                                <option value="1">产品编号</option>
                                <option value="2">产品名称</option>
                                <option value="3">产品种类</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" name="searchPro" placeholder="请输入" autocomplete="off" class="layui-input"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()">
                        <i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加产品','plan_pro_add',800,600)">
                        <i class="layui-icon"></i>添加</button></div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" id="checkAllElems" lay-filter="checkAllElems" lay-skin="primary">
                            </th>
                            <th>产品编号</th>
                            <th>产品名称</th>
                            <th>产品种类</th>
                            <th>状态</th>
                            <th>产品介绍</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${requestScope.proList}" var="eve">
                            <tr>
                            <td><input type="checkbox" id="${eve.proNumber}" name="checkElem" lay-skin="primary"></td>
                                <td>${eve.proNumber}</td>
                                <td>${eve.proName}</td>
                                <td>${eve.proKind}</td>
                                <c:choose>
                                    <c:when test="${eve.status==0}"><td style="color: red">停产</td></c:when>
                                    <c:when test="${eve.status==1}"><td>有效产品</td></c:when>
                                    <c:otherwise><td style="color:yellow">未知状态</td></c:otherwise>
                                </c:choose>
                                <td><a style="color:blue" onclick="xadmin.open('产品介绍','plan_pro_introduction?proNumber=${eve.proNumber}',800,600)">产品介绍</a></td>
                                <td class="td-manage">
                                    <a title="编辑" onclick="xadmin.open('编辑','plan_pro_edit?proNumber=${eve.proNumber}')" href="javascript:;">
                                        <i class="layui-icon">&#xe63c;</i></a>
                                    <a title="删除" onclick="member_del(this,'${eve.proNumber}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i></a>
                                </td>
                            </tr>
                            </c:forEach>
                        </tbody>
                    </table>
                </div>
<%--                //分页--%>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                            <a class="prev" href="proList?page=${requestScope.proListOf.navigateFirstPage}">&lt;&lt;</a>
                            <c:forEach items="${requestScope.proListOf.navigatepageNums}" var="eve">
                                <c:if test="${requestScope.proListOf.pageNum==eve}">
                                    <span class="current">${eve}</span>
                                </c:if>
                                <c:if test="${requestScope.proListOf.pageNum!=eve}">
                                    <a class="num" href="proList?page=${eve}">${eve}</a>
                                </c:if>
                            </c:forEach>
                            <a class="next" href="proList?page=${requestScope.proListOf.navigateLastPage}">&gt;&gt;</a></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>layui.use(['laydate', 'form'],
    function() {
        var laydate = layui.laydate;
        var form=layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


        //监听全选
        form.on("checkbox(checkAllElems)",function(data){
            console.log(data.elem.checked);
            let check = document.getElementsByName("checkElem");
            if (data.elem.checked===true){
                for (const x of check) {
                    x.setAttribute("checked","checked");
                    console.log(x);
                    console.log(x.checked);
                    form.render('checkbox');
                }
            }
            if (data.elem.checked===false){
                for (const x of check) {
                    x.removeAttribute("checked");
                    console.log(x);
                    console.log(x.checked);
                    form.render('checkbox');
                }
            }
            // console.log(check);
            // console.log(checkAll.checked);

        });
        //监听提交
        // form.on("submit(search)",function (data){
        //     console.log(data.field);
        //     $.ajax({
        //         url:"checkPro",
        //         type:"post",
        //         data:JSON.stringify(data.field),
        //         dataType:"json",
        //         contentType:"application/json",
        //         success:function (result){
        //
        //         }
        //     })
        // })
    });

/*用户-停用*/


/*用户-删除*/
function member_del(obj, proNumber) {
    layer.confirm('确认要删除吗？',
        function(index) {
            //发异步删除数据
            console.log(JSON.stringify(proNumber));
            console.log(proNumber);
            $.ajax({
                url:"deletePro",
                type:"post",
                data:JSON.stringify(proNumber),
                dataType:"json",
                contentType:"application/json;charset=utf-8",
                success:function (result){
                    if (result.code===200){
                        $(obj).parents("tr").remove();
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        });
                    }else{
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        });
                    }
                }
            })

        });
}
//批量删除
function delAll(argument) {
var check=document.getElementsByName("checkElem");
var nameList=[];
    for (const x of check) {
        if (x.checked===true){
            nameList.push(x.id);
        }
    }
    console.log(JSON.stringify(nameList));
    console.log(nameList);
    layer.confirm('确认要删除选中内容吗？',
        function() {
        $.ajax({
            url:"deleteChecked",
            type: "post",
            data:JSON.stringify(nameList),
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success:function (result){
                //捉到所有被选中的，发异步进行删除
                if (result.code===200){
                    layer.msg(result.msg, {
                        icon: 1
                    });
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                }else {
                    layer.msg(result.msg, {
                        icon: 1
                    });
                }
            }
        })
        });
}


</script>

</html>